﻿using System;

using System.Collections.Generic;
using System.Text;
using Fluid.Controls;
using System.Drawing;
using PasswordSafe.Templates;
using PasswordSafe.Xml;
using PasswordSafe.Classes;

namespace PasswordSafe
{
    public class PasswordsListBox : ListBoxBase
    {
        protected override void InitControl()
        {
            base.InitControl();
            //ShowHeader = false;
            ItemHeight = 32;

            ItemTemplate = new PasswordTemplate();
        }

        private NotifyList passwords;

        public NotifyList Passwords
        {
            get { return passwords; }
            set
            {
                if (passwords != value)
                {
                    passwords = value;
                    //ShowHeader = value != null && value.Count > 3 && value[0] is IGroupHeader;
                    DataSource = value;
                }
            }
        }

        protected override void OnItemClick(int index)
        {
            base.OnItemClick(index);
            SelectedItemIndex = index;
            NavigateForward();
        }

        public override bool NavigateForward()
        {
            PasswordData password = passwords[SelectedItemIndex] as PasswordData;

            SelectedPassword = password;
            if (password != null)
            {
                if (PasswordSelected != null) PasswordSelected(this, EventArgs.Empty);
            }
            return true;
        }
        public PasswordData SelectedPassword { get; private set; }

        public event EventHandler PasswordSelected;

        public override void AddItem()
        {
            
        }

    }
}
